<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>城市管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span class="separator"></span>
            <span>关键词：</span>
            <input id="keyname" name="keyname" class="mini-textbox" emptyText="行政区划代码/行政区划名称/行政区划英文名称/行政区划英文简称" style="width: 400px"/>

            <span class="separator"></span>
            <% if(so.hasPermission("xtcity:query")){%>
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            <% } %>

            <% if(so.hasPermission("xtcity:queryCndClear")){%>
                <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
            <% } %>

        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/basic_data_manage/xt_city/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="true">
            <div property="columns">
<!--                <div field="code" width="140" headerAlign="center" align="center" allowSort="true">行政区划代码</div>-->
                <div field="name" width="140" headerAlign="center" align="center" allowSort="true">行政区划名称</div>
                <div field="pid" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">父行政区划名称</div>
                <div field="nameEn" width="140" headerAlign="center" align="center" allowSort="true">行政区划拼音</div>
                <div field="shortNameEn" width="140" headerAlign="center" align="center" allowSort="true">行政区划首字母</div>
                <div field="status" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">状态标识</div>
<!--                <div width="140" headerAlign="center" align="center" renderer="operRenderer">操作</div>-->
            </div>
        </div>
    </div>
    <!--编辑窗口-->
    <div id="updatePanel" class="mini-window" title="城市管理" style="width:700px;height:400px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="insertOrUpdateSaveBtn" name="insertOrUpdateSaveBtn" class="mini-button" iconCls="icon-save" onclick="saveInsertOrUpdate()">保存</a>
        </div>
        <div id="cityForm">
            <table style="width: 100%">
                <tr>
                    <td><label>ID:</label></td>
                    <td colspan="3"><input id="id" name="id"  class="mini-textbox" />
                    </td>
                </tr>
                <tr>
                    <td><label>行政区域名称:</label></td>
                    <td><input name="name"  class="mini-textbox" required="true" requiredErrorText="行政区域名称不能为空" /></td>
                    <td><label>行政区域代码:</label></td>
                    <td><input name="code"  class="mini-textbox" required="true" requiredErrorText="行政区域代码不能为空"/></td>
                </tr>
                <tr>
                    <td><label>父行政区划ID:</label></td>
                    <td><input name="pid"  class="mini-textbox" required="false" requiredErrorText="父行政区划ID不能为空"/></td>
                </tr>
                <tr>
                    <td><label>行政区域英文名称:</label></td>
                    <td><input name="nameEn"  class="mini-textbox" required="false" requiredErrorText="机场名称简称不能为空"/></td>
                    <td><label>行政区域英文简称:</label></td>
                    <td><input name="shortNameEn"  class="mini-textbox" required="false" requiredErrorText="机场简称全拼音能为空"/></td>
                </tr>
                <tr>
                    <td><label>状态:</label></td>
                    <td colspan="3"><input id="status" name="status" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                           required="true" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有是否有效" emptyText="请输入状态"/></td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        let grid = mini.get("datagrid1");
        let oper;
        let cityForm = new mini.Form("#cityForm");

        $(function () {
            // 加载列表数据
            grid.load();
            // 加载弹出窗口的有效性下拉列表  1	0	有效标志	XT_DIC_STATUS
            let jsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_STATUS");
            mini.get("status").load(jsonData);
        });

        function search() {
            let form = new mini.Form("#queryForm");
            let data = form.getData(true);
            grid.load(data);
        }

        function clearSearch() {
            let form = new mini.Form("#queryForm");
            form.clear();
        }

        function add(){
            cityForm.clear();
            oper = OPER_ADD();
            //有效无效默认值为有效
            mini.get("status").setValue(2);
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");
        }

        function update(){
            cityForm.clear();
            // 获取当前选中的行
            let row = grid.getSelected();
            if(!row){
                mini.alert("请选择要编辑的行!","字典编辑",null);
                return;
            }
            cityForm.setData(row);
            oper = OPER_UPDATE();
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");
        }

        //新增保存或修改保存
        function saveInsertOrUpdate(){
            // 添加并保存
            cityForm.validate();
            if (cityForm.isValid() == false){
                public_showErrorTips("请将信息填写完整再进行下一步！");
                return;
            }
            let data = cityForm.getData(true);

            let methodName = oper == OPER_ADD() ? "insert" : "update";
            let ret = public_getServerData("${base}/pages/basic_data_manage/xt_city/" + methodName,data);
            public_showTip(ret);
            if(ret.ok) {
                // 重新刷新数据
                grid.load();
                refreashCache();
                public_onCancel('updatePanel');
            }
        }


        function deleteCity(){
            let select = grid.getSelected();
            if(select == null){
                public_showErrorTips("未选中");
                return;
            }
            mini.confirm(
                "确定删除？",
                "确定？",
                function(action) {
                    if (action == "ok") {
                        console.log(select.id);
                        let ret = public_getServerData("${base}/pages/basic_data_manage/xt_city/delete?id=" + select.id);
                        public_showTip(ret);
                        if(ret.ok) {
                            refreashCache();
                            // 重新刷新数据
                            grid.removeRow(select, true);
                        }
                    }
                });
        }

        //操作
        function operRenderer(e) {
            let record = e.record;
            let id = record.id;
            let s = "";
            s += '<a class="New_Button" href="javascript:update(\'' + id + '\')">编辑</a>';
            return s;
        }

        // 刷新缓存，把刷新的缓存放到父页面，应当调用父级页面方法刷新
        function refreashCache() {
            parent.window.loadCache();
        }

    </script>
</body>
</html>